import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  // 关键配置：生产环境基础路径
  base: '/web/',  // 必须与Nginx的location匹配
  
  server: {
    host: '0.0.0.0',
    port: 5173,
    proxy: {
      '/api': {
        target: 'https://www.xaoji.com:2346',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
      '/formal': {
        target: 'https://www.xaoji.com:8384',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/formal/, ''),
      },
      '/media': {
        target: 'http://35810169ff.qicp.vip:46758',
        // target: 'http://192.168.2.46:7860',
        changeOrigin: true,
        // rewrite: (path) => path.replace(/^\/media/, ''),
      }
    }
  },
  
  // 优化构建输出
  build: {
    assetsDir: 'assets',
    rollupOptions: {
      output: {
        assetFileNames: 'assets/[name]-[hash][extname]',
        chunkFileNames: 'assets/[name]-[hash].js',
        entryFileNames: 'assets/[name]-[hash].js'
      }
    }
  }
})